package com.chenfan.common.dto;

import com.chenfan.common.config.SettleConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.math.BigDecimal;

@ApiModel(description = "基础分页")
public class PagerDTO extends UserPrivilegeDTO {

    /**
     * 分页开始数 通过pageNum计算
     */
    @ApiModelProperty(hidden = true)
    private Integer offset;

    /**
     * 当前页码
     */
    @ApiModelProperty(required = true, value = "页数")
    private Integer pageNum = 1;

    /**
     * 显示数量
     */
    @ApiModelProperty(required = true, value = "显示数量")
    private Integer pageSize = 15;

    private Integer pageCount;

    private BigDecimal sum = BigDecimal.ZERO;

    public BigDecimal getSum() {
        return sum;
    }

    public void setSum(BigDecimal sum) {
        this.sum = sum;
    }

    public Integer getPageCount() {
        return pageCount;
    }

    public void setPageCount(Integer pageCount) {
        this.pageCount = pageCount;
    }

    public Integer getPageNum() {
        if (pageNum == null) {
            setPageNum(SettleConstant.DEFAULT_PAGE_NO);
        }
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    /**
     * @return 返回分页起始数
     */
    public Integer getOffset() {
        if (getPageNum() != null && getPageSize() != null && offset == null) {
            setOffset((pageNum - 1) * pageSize);
        }
        return offset;
    }

    public void setOffset(Integer offset) {
        this.offset = offset;
    }

    public Integer getPageSize() {
        if (pageSize == null) {
            setPageSize(SettleConstant.DEFAULT_PAGE_SIZE);
        }
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }
}
